import logging
import os
import allure
from utils.data_preprocessor import *

@allure.step("1.解析测试数据")
def analyse_case(case):
    method = case["method"]
    # 判断url是不是mock
    url = os.environ["MOCK_URL"]+case["path"] if case["is_mock"] else os.environ["URL"]+case["path"]
    headers = eval(case["headers"]) if isinstance(case["headers"],str) else None
    params = eval(case["params"]) if isinstance(case["params"],str) else None
    data = eval(case["data"]) if isinstance(case["data"], str) else None
    json = eval(case["json"]) if isinstance(case["json"],str) else None
    files = eval(case["files"]) if isinstance(case["files"],str) else None

    request_data = {
        "method":method,
        "url":url,
        "headers":headers,
        "params":params,
        "data":data,
        "json":json,
        "files":files
    }
    logging.info(f"1.解析请求数据，请求数据为：{request_data}")
    allure.attach(f"{request_data}",name="解析请求数据") #在测试步骤中显示一个可展开的文本块，标题为“解析请求数据”
    return request_data

